/* Created By Micha Sherman & Yuval Poleg, google workshop 2012
 * 
 */

package com.gps.misc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.appengine.utils.AeLoadingCenter;
import com.appengine.utils.GsonUtils;
import com.appengine.utils.SavingAndLoadingCenter;
import com.datatypes.ActivityTracks;
import com.datatypes.FriendsZone;
import com.datatypes.User;
import com.datatypes.UserTracks;
import com.gps.track.GpsTrackingActivitySolo;
import com.sporteamws.R;
import com.sporteamws.SharedPref;

public class Run extends Activity implements android.view.View.OnClickListener {

	// global variables
	Button solo;
	Button ghost;
	User user = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// setup content view
		setContentView(R.layout.run);

		solo = (Button) findViewById(R.id.bSolo);
		ghost = (Button) findViewById(R.id.bGhost);
		user = SavingAndLoadingCenter.loadUser(SharedPref.facebookID, this);
		if (user == null) {
			user = new User(20, "" + 12345, "test", "Ftest", null, 0.9, "male",
					65);
			SavingAndLoadingCenter.saveUser(user, this);
			SavingAndLoadingCenter.saveUserTracks(user.GetFacebookID(),
					new UserTracks(user), this);
			SavingAndLoadingCenter.saveActivityTracks(user.GetFacebookID(),
					new ActivityTracks(user), this);
			SavingAndLoadingCenter.saveFriendsZone(user.GetFacebookID(),
					new FriendsZone(5), this);
		}

		ghost.setOnClickListener(this);
		solo.setOnClickListener(this);
	}

	public void onClick(View v) {
		if (v.getId() == R.id.bSolo) {
			Intent intent = new Intent(this, GpsTrackingActivitySolo.class);
			Bundle bundle = new Bundle();
			bundle.putBoolean("SOLO", true);
			String usrStr = GsonUtils.ConvertUserToGsonString(user);
			bundle.putString("USER", usrStr);
			intent.putExtras(bundle);
			startActivity(intent);

		} else if (v.getId() == R.id.bGhost) {
			Intent intent = new Intent(this, GhostRecord.class);
			Bundle bundle = new Bundle();
			String usrStr = GsonUtils.ConvertUserToGsonString(user);
			bundle.putString("USER", usrStr);
			intent.putExtras(bundle);
			AeLoadingCenter.LoadTracks(user.GetFacebookID(), intent, this);
		}

	}

	@Override
	protected void onResume() {
		super.onResume();

	}

}
